// 点击图标打开侧边栏扩展
chrome.sidePanel.setPanelBehavior({ openPanelOnActionClick: true }).catch((error) => console.error(error));

console.log("加载后后台程序")

chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
    // 检查页面是否已经加载完成
    console.log(changeInfo.url)
    if (changeInfo.status === 'complete') {
        let currentUrl = tab.url
        console.log(currentUrl)
        const userWebUrl = "http://userweb.lsmedia.com/"
        // 注入内容脚本
        console.log("页面加载完成了")
        if (currentUrl.includes(userWebUrl)) {
            chrome.scripting.executeScript({
                target: { tabId: tabId },
                files: ["sidebar/js/content/loginContent.js"]
            }).then(() => {
                console.log(`登录页注册成功`);
            });
            console.log(`进入到登录页`);
        }
        let message = {
            action: 'noticeEvent',
        }
        chrome.runtime.sendMessage(message, function (response) { });
        //
        // chrome.tabs.sendMessage(tabId, message, function (response) {});
    }
});

